package com.ruoyi.wechat.service.impl;

import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.wechat.domain.CampFacility;
import com.ruoyi.wechat.domain.FacilityTypeVO;
import com.ruoyi.wechat.mapper.CampFacilityMapper;
import com.ruoyi.wechat.mapper.FacilityTypeMapper;
import com.ruoyi.wechat.service.IWxFacilityTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WxFacilityTypeServiceImpl implements IWxFacilityTypeService {

    @Autowired
    private FacilityTypeMapper facilityTypeMapper;

    @Autowired
    private CampFacilityMapper campFacilityMapper;

    /**
     * 查询所有启用的服务设施类型以及对应的服务设施
     * @return
     */
    @Override
    public List<FacilityTypeVO> selectTypeAndFacility() {
        return facilityTypeMapper.selectFacilityAndType();
    }

    @Override
    public List<FacilityTypeVO> campFacilityListByCampId(String campId) {
        return facilityTypeMapper.selectFacilityTypeAndFacilityListByCampId(campId);
    }

    @Override
    public int insertCampFacility(String campId, String[] facilityIds) {
        //先删除营地下的服务设施
        campFacilityMapper.deleteCampFacilityByCampId(campId);
        //然后插入新的服务设施
        for (String facilityId : facilityIds) {
            CampFacility campFacility = new CampFacility();
            campFacility.setCfId(IdUtils.randomUUID());
            campFacility.setCampId(campId);
            campFacility.setFacilityId(facilityId);
            campFacilityMapper.insertCampFacility(campFacility);
        }
        return 1;
    }

    @Override
    public int deleteCampFacilityByCampId(String campId) {
        return campFacilityMapper.deleteCampFacilityByCampId(campId);
    }
}
